﻿using DevExpress.Utils;
using EyFramework.Common;
using EyFramework.Library;
using Ncov2019.Core.Service;
using Ncov2019.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EyFramework.Sys.Core;

namespace Ncov2019
{
    public partial class FrmNcovRegist : FrmDevBase
    {
        private List<GridColumnInfo> columnInfos = new List<GridColumnInfo>();

        private INcovRegistService ncovRegistService;

        public FrmNcovRegist()
        {
            InitializeComponent();
        }

        private void InitForm()
        {
            gvData.ShowRowNum();
            gcData.ShowContextMenu(this.components);//显示右键导出功能
            #region
            columnInfos.Add(new GridColumnInfo("PATIENT_ID", "病历号码", 100) {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("PATIENT_NAME", "姓名", 100) {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("BIRTHDAY", "出生日期", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("SEX", "性别", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("ID_TYPE", "证件类型", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("ID_NO", "证件号码", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("TELPHONE", "联系电话", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("COMPANY", "工作单位", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("CONTACT_NM", "联系人姓名", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("CONTACT_ID_NO", "联系人证件", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("ADDRESS", "联系地址", 100) { 
                COL_READONLY=false
            });
            columnInfos.Add(new GridColumnInfo("JIUZHENKS", "就诊科室", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("JKM", "健康码", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("BIRTHPLACE", "出生地", 100)
            {
                COL_READONLY = false
            });
            columnInfos.Add(new GridColumnInfo("TEMPERATURE", "体温", 100));
            columnInfos.Add(new GridColumnInfo("SFPH", "是否陪护", 100));
            columnInfos.Add(new GridColumnInfo("ZGWDQ", "2周内是否到过中高位地区或接触过来自中高危地区的人员", 100));
            columnInfos.Add(new GridColumnInfo("JJXFR", "2周内周围是否有聚集性发热、咳嗽等患者", 100));
            columnInfos.Add(new GridColumnInfo("XGQZHZ", "2周内是否接触新冠确诊患者", 100));
            columnInfos.Add(new GridColumnInfo("SFFR", "是否出现发热(>=37.3)", 100));
            columnInfos.Add(new GridColumnInfo("HXDZZ", "是否出现气促、咳嗽、腹泻、乏力等呼吸道感染症状", 100));
            columnInfos.Add(new GridColumnInfo("TRYW", "是否服用退热药物", 100));
            columnInfos.Add(new GridColumnInfo("REGIST_DT", "流调登记时间", 100)
            {
                COL_READONLY = false,
                Formattype = FormatType.DateTime,
                Formatstring = "yyyy-MM-dd HH:mm:ss"
            });
            #endregion
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            ShowLoading();
            try
            {
                QueryData();
            }
            finally
            {
                CloseLoading();
            }
        }

        private void QueryData()
        {
            NcovInfoParam param = new NcovInfoParam()
            {
                CHT_ID = teChtId.Text.Trim(),
                PAT_NM = tePatnm.Text.Trim(),
                START_DT = de_start.DateTime.ToString("yyyy-MM-dd"),
                END_DT = de_end.DateTime.ToString("yyyy-MM-dd")
            };
            var ncovRecords = ncovRegistService.QueryRegistInfo(param);
            ncovRecords.ForEach(p =>
            {
                p.SEX = SysCache.GetDictVal(p.SEX, SysConstants.DICT_SEX);
                p.BIRTHDAY = Convert.ToDateTime(p.BIRTHDAY).ToString("yyyy-MM-dd");
            });
            gcData.DataSource = ncovRecords;
            DevPublic.SetGridControlView(gvData, columnInfos, true, true);
        }

        private void FrmNcov_Load(object sender, EventArgs e)
        {
            ncovRegistService = Globals.GetService<INcovRegistService>();
            InitForm();
            de_start.Text = ncovRegistService.GetCurrentDate("YYYY-MM-DD");
            de_end.Text = de_start.Text;
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            //修改患者信息
        }
    }
}